package com.wenwei.sharebox.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/15.
 */
public abstract class BaseActivity extends AppCompatActivity {

    public static Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AtyContainer.getInstance().addActivity(this);
        setContentView(setLayoutResourceId());//设置布局
        mContext = this;
        ButterKnife.bind(this);
        init();
        initView();
        initData();
    }

    //供子类扩展操作
    protected void init(){};
    protected void initView(){};
    protected void initData(){};

    //封装子类公有属性,绑定布局
    public abstract int setLayoutResourceId();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    public void goActivity(Context _this, Class<? extends Activity> _class){
        startActivity(new Intent(_this,_class));
    }

    public void goActivity(Context _this,Class<? extends Activity> _class,Bundle bl){
        startActivity(new Intent(_this,_class).putExtras(bl));
    }

    public void goActivity(Context _this,Class<? extends Activity> _class,Bundle bl,int requestCode){
        if(bl == null){
            startActivityForResult(new Intent(_this,_class),requestCode);
        }else{
            startActivityForResult(new Intent(_this,_class).putExtras(bl),requestCode);
        }
    }

    public void showToast(String s){
        Toast.makeText(mContext,s,Toast.LENGTH_SHORT).show();
    }
}
